package com.wing.purchase.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 采购订单
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("pur_purchase_order")
public class PurchaseOrder extends BaseEntity<PurchaseOrder> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Status implements IEnum<Integer> {

        /**
        * 待审核
        */
        stayAudit(0,"待审核"),
        /**
        * 审核成功
        */
        success(1,"审核成功"),
        /**
        * 审核拒绝
        */
        fail(2,"审核拒绝"),
        /**
        * 已关闭
        */
        closed(3,"已关闭");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum Source implements IEnum<Integer> {

        /**来源:purchase(0,采购订单);cabinet(1,智能柜采购订单)
         * 待审核
         */
        purchase(0,"采购订单"),
        /**
         * 审核成功
         */
        cabinet(1,"智能柜采购订单");
        private int code;
        private String desc;

        Source(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum ShippingStatus implements IEnum<Integer> {

        /**
        * 待发货
        */
        stayDelivery(0,"待发货"),
        /**
        * 发货中
        */
        delivering(1,"发货中"),
        /**
        * 发货完成
        */
        shipped(2,"发货完成");

        private int code;
        private String desc;

        ShippingStatus(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 是否已签约
     */
    private String hasSign;

    /**
     * 合同id
     */
    private Long contractId;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 订单编号
     */
    private String sn;

    /**
     * 部门ID
     */
    private Long departmentId;

    /**
     * 供应商ID
     */
    private Long supplierId;

    /**
     * 业务员ID
     */
    private Long personnelId;

    /**
     * 审核人
     */
    private Long auditor;

    /**
     * 变更人
     */
    private Long changer;

    /**
     * 关闭人
     */
    private Long shutter;

    /**
     * 状态
     */
    private Status status;

    /**
    * 状态描述
    */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }

    /**
     * 来源
     */
    private Source source;

    /**
     * 来源描述
     */
    @TableField(exist = false)
    private String sourceDesc;

    public String getSourceDesc() {
        return source == null ? null : source.getDesc();
    }


    /**
     * 审核失败原因
     */
    private String reason;

    /**
     * 报价单ID
     */
    private Long purchaseQuotationId;

    /**
     * 发货状态
     */
    private ShippingStatus shippingStatus;

    /**
    * 发货状态描述
    */
    @TableField(exist = false)
    private String shippingStatusDesc;

    public String getShippingStatusDesc() {
        return shippingStatus == null ? null : shippingStatus.getDesc();
    }

    /**
     * 询价单号
     */
    private String inquiryNo;

    /**
     * 采购类型ID
     */
    private Long purchaseTypeId;

    /**
     * 采购订单明细集合
     */
    @TableField(exist = false)
    private List<PurchaseOrderDetail> purchaseOrderDetails = new ArrayList<>();


    /**
     * 采购类型：1.原材料采购 2.办公用品采购
     */
    private Integer purchaseType;

    /**
     * 紧急程度：1.紧急采购 2.一般采购
     */
    private Integer emergencyDegree;

    /**
     * 岗位id
     */
    private String postName;

    /**
     * 计划到货时间
     */
    private LocalDateTime planOnTime;

    /**
     * 预计交付时间
     */
    private LocalDateTime planDeliverTime;

    /**
     * 录入时间(动态)
     */
    private LocalDateTime enterTime;

}
